{extend name="layout:base" /}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="test-table-reload-btn">
                开始时间
                <div class="layui-input-inline">
                    <input type="text" name="startTime" value="" class="layui-input" lay-verify="required" autocomplete="off" id="startTime" placeholder="yyyy-MM-dd">
                </div>
                结束时间
                <div class="layui-input-inline">
                    <input type="text" name="endTime" value="" class="layui-input" lay-verify="required" autocomplete="off" id="endTime" placeholder="yyyy-MM-dd">
                </div>
                <div class="layui-inline">
                    <select name="typeid" id="typeid" lay-filter="typeid">
                        <option value="">请选择平台</option>
                        <option value="1">百度</option>
                        <option value="2">360</option>
                        <option value="3">百度移动端</option>
                        <option value="4">sogou</option>
                        <option value="5">神马</option>
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="seoid" id="seoid" lay-filter="seoid">
                        <option value="">选择优化师</option>
                        {volist name="seo" id="vo" }
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
                <div class="layui-inline">
                    <select name="isindex" id="isindex" lay-filter="isindex">
                        <option value="">是否首页</option>
                        <option value="1">是</option>
                        <option value="2">否</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="keywords" id="keywords" value="" autocomplete="off" class="layui-input" placeholder="关键词">
                </div>
                <button class="layui-btn" data-type="reload">搜索</button>

            </div>
        </div>
        <div class="layui-card-body">
            <table id="tbList" class="layui-table" lay-filter="tbList" ></table>
            <script type="text/html" id="state">
                <input type="checkbox" name="state" value="{{d.id}}" lay-skin="switch" lay-text="正常|停用" lay-filter="state" {{ d.state== 1 ? 'checked' : '' }}
                {if condition="$Think.session.admin.levelNum <10 "}disabled{/if} >
            </script>
            <script type="text/html" id="type">
                {{#  if(d.typeid ==1){ }}百度{{#  } }}
                {{#  if(d.typeid ==2){ }}360{{#  } }}
                {{#  if(d.typeid ==3){ }}百度移动端{{#  } }}
                {{#  if(d.typeid ==4){ }}sogou{{#  } }}
                {{#  if(d.typeid ==5){ }}神马{{#  } }}
            </script>

        </div>
    </div>
</div>

{/block}

{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'util','form','laydate'], function () {
        var $ = layui.$,form = layui.form,layer = layui.layer,table = layui.table,laydate = layui.laydate;


        var insStart = laydate.render({
            elem: '#startTime'
            ,type: 'datetime'
            ,max: 0
            ,done: function(value, date){
                //更新结束日期的最小日期
                insEnd.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });

                //自动弹出结束日期的选择器
                insEnd.config.elem[0].focus();
            }
        });

        //结束日期
        var insEnd = laydate.render({
            elem: '#endTime'
            ,type: 'datetime'
            ,max: 0
            ,done: function(value, date){
                //更新开始日期的最大日期
                insStart.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        //表格
        table.render({
            elem: '#tbList',
            url: "{:url('getList')}",
            toolbar: '#toolbarDemo',
            totalRow: true,
            cellMinWidth: 80,
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {field: 'id', fixed: 'left', title: 'ID',width:66, totalRowText: '合计',sort: false},
                {field: 'url',fixed: 'left',title: '网址'},
                {field: 'Name',fixed: 'left',title: '关键词'},
                {field: 'typeid',title: '平台', templet:'#type'},
                {field: 'keypm',  title: '当前排名'},
                {field: 'money',  title: '消费', totalRow: true},
                {field: 'intime',  title: '扣费时间',width:180},
            ]],
            page: true,
            limit:15
        });


        // 监听工具条
        table.on('tool(tbList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'show_web') {

            }else if(obj.event === 'show_key'){

            }
        });


        //操作
        var $ = layui.$, active = {
            reload: function(){
                var startTime=$('#startTime').val();
                var endTime=$('#endTime').val();
                var typeid=$('#typeid').val();
                var seoid=$('#seoid').val();
                var isindex=$('#isindex').val();
                var keywords=$('#keywords').val();

                //执行重载
                table.reload('tbList', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        startTime: startTime
                        ,endTime: endTime
                        ,typeid: typeid
                        ,seoid: seoid
                        ,isIndex: isindex
                        ,keywords: keywords
                    }
                });

            }
        };

        // $("#btnAdd").on('click', function () {
        //     var type = $(this).data('type');
        //     active[type] ? active[type].call(this) : '';
        // });

        $('.test-table-reload-btn .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
{/block}